'''
100000以内质数之和,将100000分成4份,创建
4个子进程,每个求其中一份,最后所有子执行完为止.
统计一共用了多少时间
'''
from multiprocessing import Process
import time


def func(start_num, end_num):
    for i in range(start_num, end_num):
        for j in range(2, i//2+1):
            if i % j == 0:
                break
        # else:
        #     print(i)


temp = []
start_time = time.time()
for i in [(1, 25001), (25001, 50001), (50001, 75001), (75001, 100001)]:
    process = Process(target=func, args=i)
    temp.append(process)
    process.start()

for i in temp:
    i.join()
end_time = time.time()
total_time = (end_time - start_time)
print(f'执行结束,一共用了{total_time}秒')
